package com.songcha.module_bookdetail.ui.decoration

import android.graphics.Rect
import android.view.View
import androidx.core.view.size
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.songcha.library_common.util.dp2px



class CommentReportTypeItemDecoration() : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val layoutParams: GridLayoutManager.LayoutParams =
            view.layoutParams as GridLayoutManager.LayoutParams

        if(parent.adapter==null) return

        if(layoutParams.spanIndex%2==0){
            outRect.left=0.dp2px()
            outRect.right=19.dp2px()
            outRect.top=0f.dp2px().toInt()
            if(layoutParams.absoluteAdapterPosition<parent.adapter!!.itemCount-2)
                outRect.bottom=14f.dp2px().toInt()
        }else{
            outRect.left=19.dp2px()
            outRect.right=0.dp2px()
            outRect.top=0f.dp2px().toInt()
            if(layoutParams.absoluteAdapterPosition<parent.adapter!!.itemCount-2)
                outRect.bottom=14f.dp2px().toInt()
        }

    }
}